package com.chpn.log.util;

import com.chpn.log.entity.TagGroup;
import com.chpn.log.write.WriteLogA;
import com.chpn.log.write.WriteLogB;

import java.util.concurrent.ArrayBlockingQueue;


public class TagGenerator {
    private ArrayBlockingQueue<TagGroup> tagGroups;
    private Thread thread;

    public TagGenerator(int size, String threadName){
        tagGroups = new ArrayBlockingQueue<>(size);
        thread = new Thread(this::process,threadName);
    }

    public void pushTag(TagGroup tagGroup){
        tagGroups.offer(tagGroup);
    }

    private void process(){
        while (true){
            try {
                TagGroup tagGroup = tagGroups.take();
                WriteLogA.write(tagGroup.getTagEntityA());
                WriteLogB.write(tagGroup.getTagEntityB());
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }

    public void start(){
        thread.start();
    }

}
